import pandas as pd

df1 = pd.DataFrame(
    [{"r1": 'a', "r2": 1},
     {"r1": "b", "r2": 2},
     {"r1": "c", "r2": 2},
     {"r1": "d", "r2": 3}
     ]
)
df1.set_index("r1", inplace=True)
print(df1)

df2 =pd.DataFrame(
    [{"r1": 'e', "r2": 5},
     {"r1": "f", "r2": 6}
     ]
)
df2.set_index("r1", inplace=True)
print(df2)

# 使用等于的附值方式，只会参考原有的index,新的index不会补充
all_df = pd.DataFrame()
all_df["df1"] = df1["r2"]
all_df["df2"] = df2["r2"]
print(all_df)

# concat的方式，可以合并index
all_df2 = pd.concat([df1["r2"], df2["r2"]], axis=1, sort=True)
print(all_df2)